$.ajax({
    type:"POST",
    url:"/api/message",
    success:(data)=>{
        const obj = data.data.rows
        console.log(obj)
        $(".st").text(`留言 (${obj.length})`)
        for(let i=0;i<obj.length;i++){
            if(i==0){
                $(".box").append(`
                <li class="comment rounded">
                <div class="thumb">
                    <img src=${obj[i].img} style="height:70px;width:70px;border-radius: 50%;">
                </div>
                <div class="details">
                <h4 class="name"><a href="#">${obj[i].name}</a><a style="float: right;">${obj[i].email}</a></h4>
                <span class="date">${obj[i].data}</span>
                <p>${obj[i].text}</p>
                </div>
                </li>
                `)
            }
            else if(i%2==0){
                $(".box").append(`
                <li class="comment  rounded">
                <div class="thumb">
                    <img src=${obj[i].img} style="height:70px;width:70px;border-radius: 50%;">
                </div>
                <div class="details">
                <h4 class="name"><a href="#">${obj[i].name}</a><a style="float: right;">${obj[i].email}</a></h4>
                <span class="date">${obj[i].data}</span>
                <p>${obj[i].text}</p>
                </div>
                </li>
                `)
            }else{
                $(".box").append(`
                <li class="comment child rounded">
                <div class="thumb">
                    <img src=${obj[i].img} style="height:70px;width:70px;border-radius: 50%;">
                </div>
                <div class="details">
                <h4 class="name"><a href="#">${obj[i].name}</a><a style="float: right;">${obj[i].email}</a></h4>
                <span class="date">${obj[i].data}</span>
                <p>${obj[i].text}</p>
                </div>
                </li>
                `)
            }
        }
        for(let i=0;i<obj.length/4;i++){
            $("#fy").append(`
            <li class="page-item" aria-current="page"><a class="page-link">${i+2}</a></li>
            `)
        }
    }
})
$(".tj").on("click",()=>{
    const email = $("#InputEmail").val()
    const text = $("#InputMessage").val()
    const myDate = new Date()
    const time = myDate.toLocaleString()
    $.ajax({
        type:"POST",
        url:"/api/message/add",
        data:{
            name: vid,
            img: vimg,
            email,
            text,
            sculpture: 1,
            data: time,
        },
        success:(data)=>{
            if(data.data==="you dont have any token to access the api"){
                alert("请登录后留言")
                window.location.href("../contact.html")
            }else{
                console.log("...")
            }
        }
    })
})